package com.haier.uos.springcloud.basic.controller;

import com.haier.uos.springcloud.basic.service.ICityDataService;
import com.haier.uos.springcloud.basic.service.IWeatherDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/report")
public class WeatherReportController {
    @Autowired
    private IWeatherDataService weatherDataService;
    @Autowired
    private ICityDataService cityDataService;

    @GetMapping("/cityId/{cityId}")
    public ModelAndView getReportByCityId(@PathVariable String cityId, Model model) {
        model.addAttribute("title", "我的天气预报");
        model.addAttribute("cityList", cityDataService.getCityList());
        model.addAttribute("cityId", cityId);
        model.addAttribute("report", weatherDataService.getDataByCityId(cityId).getData());

        return new ModelAndView("weather/report", "reportModel", model);
    }
}
